package org.zzz.controller;

import org.zzz.entity.Student;
import org.zzz.entity.StudentVo;
import org.zzz.entity.vo.StudentShowVo;
import org.zzz.service.StudentService;
import org.zzz.service.impl.StudentServiceImpl;
import org.zzz.utils.Result;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:58
 */
public class StudentController {

    private StudentService studentService = new StudentServiceImpl();;

    /**
     * 获取所有学生信息
     * @return
     */
    public Result<List<Student>> listAllStudent(){
        List<Student> studentList = studentService.listAllStudent();
        return !studentList.isEmpty() ? Result.success("查询成功").data(studentList) : Result.error("暂无数据");
    }

    /**
     * 查询所有学生(用于展示)
     * @return
     */
    public Result<List<StudentShowVo>> listAllStudentShow(){
        List<StudentShowVo> studentShowVos = studentService.listAllStudentShow();
        return !studentShowVos.isEmpty() ? Result.success("查询成功").data(studentShowVos) : Result.error("暂无数据");
    }

    /**
     * 根据学生姓名获取学生信息
     * @param name
     * @return
     */
    public Result<StudentShowVo> getStudentByName(String name){
        StudentShowVo studentByName = studentService.getStudentByName(name);
        return studentByName != null ? Result.success("查询成功").data(studentByName) : Result.error("查无数据");
    }

    /**
     * 根据学号查询
     * @param sid
     * @return
     */
    public Result<StudentShowVo> getStudentById(String sid){
        StudentShowVo studentVoBySid = studentService.getStudentVoBySid(sid);
        return studentVoBySid != null ? Result.success("查询成功").data(studentVoBySid) : Result.error("查无数据");
    }

    public Result<List<Student>> listStudentByClassId(String classId){
        List<Student> studentList = studentService.listStudentByClassId(classId);
        return !studentList.isEmpty() ? Result.success("查询成功").data(studentList) : Result.error("暂无数据");
    }

}
